package com.zp.base.controller.labMaintenance;

import com.zp.base.entity.labMaintenance.bo.LabVsClinicBo;
import com.zp.base.entity.labMaintenance.vo.LabVsClinicVo;
import com.zp.base.service.labMaintenance.ILabVsClinicService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 检验项目与诊疗项目对照控制器
 * 前端访问路由地址为:/base/labVsClinic
 *
 * @author zhang peng
 * @ date 2023-05-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/labVsClinic")
public class LabVsClinicController extends BaseController {

    private final ILabVsClinicService iLabVsClinicService;

    /**
     * 查询检验项目与诊疗项目对照列表 (分页)
     */
//    @SaCheckPermission("base:labVsClinic:list")
    @GetMapping("/selectPage")
    public TableDataInfo<LabVsClinicVo> selectPage (LabVsClinicBo bo, PageQuery pageQuery) {
        return iLabVsClinicService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询检验项目与诊疗项目对照列表 (不分页)
     */
//    @SaCheckPermission("base:labVsClinic:list")
    @GetMapping("/list")
    public R<List<LabVsClinicVo>> list (LabVsClinicBo bo) {
        List<LabVsClinicVo> list = iLabVsClinicService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出检验项目与诊疗项目对照列表
     */
//    @SaCheckPermission("base:labVsClinic:export")
    @Log(title = "检验项目与诊疗项目对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (LabVsClinicBo bo, HttpServletResponse response) {
        List<LabVsClinicVo> list = iLabVsClinicService.queryList(bo);
        ExcelUtil.exportExcel(list, "检验项目与诊疗项目对照", LabVsClinicVo.class, response);
    }

    /**
     * 获取检验项目与诊疗项目对照详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("base:labVsClinic:list")
    @GetMapping("/{id}")
    public R<LabVsClinicVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iLabVsClinicService.queryById(id));
    }

    /**
     * 新增检验项目与诊疗项目对照
     */
//    @SaCheckPermission("base:labVsClinic:add")
    @Log(title = "检验项目与诊疗项目对照", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody LabVsClinicBo bo) {
        return toAjax(iLabVsClinicService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改检验项目与诊疗项目对照
     */
//    @SaCheckPermission("base:labVsClinic:edit")
    @Log(title = "检验项目与诊疗项目对照", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody LabVsClinicBo bo) {
        return toAjax(iLabVsClinicService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除检验项目与诊疗项目对照
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("base:labVsClinic:remove")
    @Log(title = "检验项目与诊疗项目对照", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iLabVsClinicService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
